package main.service.mail.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;

public class WUtil {
    public static String getSentDate(Date sentDate) {
        if (sentDate == null)
            return "";
        String pattern = "yyyy年MM月dd日 E HH:mm ";

        return new SimpleDateFormat(pattern).format(sentDate);
    }

    // date to string
    public static String getDate(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }

    // 写入文件
    public static String writeStringToFile(String data, String fileName) {

        File saveDirFile = new File(EmailUtils.SAVE_DIR);
        if (!saveDirFile.exists())
            saveDirFile.mkdir();

        String savePath = EmailUtils.SAVE_DIR + "\\"+fileName+".txt";

        try {

            File file = new File(savePath);
            if (!file.exists()) {
                file.createNewFile();
            }
            PrintStream ps = new PrintStream(new FileOutputStream(file));
            ps.println(data);// 往文件里写入字符串
        } catch (Exception e) {
            e.printStackTrace();
        }
        return savePath;
    }
}
